﻿namespace ESupervision.AutoTest
{
    using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
    using System;
    using System.Collections.Generic;
    using System.CodeDom.Compiler;
    using Microsoft.VisualStudio.TestTools.UITest.Extension;
    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
    using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
    using MouseButtons = System.Windows.Forms.MouseButtons;
    using System.Drawing;
    using System.Windows.Input;
    using System.Text.RegularExpressions;


    public partial class UIMap
    {

        /// <summary>
        /// Login - Use 'LoginParams' to pass parameters into this method.
        /// </summary>
        public void Login()
        {
            #region Variable Declarations
            HtmlEdit uIUsernameEdit = this.UILogintoESupervisionEWindow.UILogintoESupervisionEDocument.UIUsernameEdit;
            HtmlEdit uIPasswordEdit = this.UILogintoESupervisionEWindow.UILogintoESupervisionEDocument.UIPasswordEdit;
            HtmlInputButton uILoginButton = this.UILogintoESupervisionEWindow.UILogintoESupervisionEDocument.UILoginFormCustom.UILoginButton;
            #endregion

            // Type 'h' in 'User name' text box
            Keyboard.SendKeys(uIUsernameEdit, this.LoginParams.UIUsernameEditSendKeys, ModifierKeys.None);

            // Type '********' in 'Password' text box
            uIPasswordEdit.Password = this.LoginParams.UIPasswordEditPassword;

            // Click 'Log in' button
            Mouse.Click(uILoginButton, new Point(43, 24));
        }

        public void Login(String userName)
        {
            #region Variable Declarations
            HtmlEdit uIUsernameEdit = this.UILogintoESupervisionEWindow.UILogintoESupervisionEDocument.UIUsernameEdit;
            HtmlEdit uIPasswordEdit = this.UILogintoESupervisionEWindow.UILogintoESupervisionEDocument.UIPasswordEdit;
            HtmlInputButton uILoginButton = this.UILogintoESupervisionEWindow.UILogintoESupervisionEDocument.UILoginFormCustom.UILoginButton;
            #endregion

            // Type 'h' in 'User name' text box
            Keyboard.SendKeys(uIUsernameEdit, userName, ModifierKeys.None);

            // Type '********' in 'Password' text box
            uIPasswordEdit.Password = this.LoginParams.UIPasswordEditPassword;

            // Click 'Log in' button
            Mouse.Click(uILoginButton, new Point(43, 24));
        }
        public virtual LoginParams LoginParams
        {
            get
            {
                if ((this.mLoginParams == null))
                {
                    this.mLoginParams = new LoginParams();
                }
                return this.mLoginParams;
            }
        }

        private LoginParams mLoginParams;

        /// <summary>
        /// Log off E-Supervision
        /// </summary>
        public void Logoff()
        {
            #region Variable Declarations
            HtmlHyperlink uILogoffHyperlink = this.UIHomePageESupervisonIWindow.UIHomePageESupervisonDocument.UILogoutFormCustom.UILogoffHyperlink;
            #endregion

            // Check Log off link exists
            if(uILogoffHyperlink.Exists)
                // Click 'Log off' link
                Mouse.Click(uILogoffHyperlink, new Point(40, 24));
        }

        public bool isLogIn()
        {
            #region Variable Declarations
            HtmlHyperlink uILogoffHyperlink = this.UIHomePageESupervisonIWindow.UIHomePageESupervisonDocument.UILogoutFormCustom.UILogoffHyperlink;
            #endregion

            return uILogoffHyperlink.Exists;
        }
    }
    /// <summary>
    /// Parameters to be passed into 'Login'
    /// </summary>
    [GeneratedCode("Coded UITest Builder", "12.0.21005.1")]
    public class LoginParams
    {

        #region Fields
        /// <summary>
        /// Type 'h' in 'User name' text box
        /// </summary>
        public string UIUsernameEditSendKeys = "hiep.tang";

        /// <summary>
        /// Type '********' in 'Password' text box
        /// </summary>
        public string UIPasswordEditPassword = "MTnqGLWWNjOWwjF8wGxtdQhZ43ocezNy";
        #endregion
}
}
